Ext.namespace("Site");

Site.Add = function() {
	this.site_id=new Ext.form.Hidden({});
	this.site_num = new Ext.form.TextField({
		fieldLabel: '基站编号',
		allowBlank: false,
		blankText: '请填写基站编号',
		maxLength:10
	});
	this.site_title = new Ext.form.TextField({
		fieldLabel: '基站名称',
		allowBlank: false,
		blankText: '请填写基站名称',
		maxLength:100
	});
	this.site_att = new Ext.form.TextField({
		fieldLabel: '基站属性',
		blankText: '请填写基站属性',
		maxLength:100
	});
	this.site_position = new Ext.form.TextField({
		fieldLabel: '基站地址',
		allowBlank: false,
		blankText: '请填写基站地址',
		maxLength:100
	});
	this.site_dep = new Ext.form.TextField({
		fieldLabel: '维护单位',
		blankText: '请填写维护单位',
		maxLength:150
	});
	this.power = new Ext.form.TextField({
		fieldLabel: '供电单位',
		blankText: '请填写供电单位',
		maxLength:150
	});
	this.power_ensure=new Ext.form.ComboBox({
			width: 130,
			fieldLabel:'有无用电保障',
			displayField:'text',
			valueField:'value',
			triggerAction: 'all',
			mode:'local',
			editable: false,
			emptyText:'请选择',						
			store: new Ext.data.SimpleStore({
			fields:['value','text'],
			data:OMS.SITE_FLAG
			})
		});
	this.site_box=new Ext.form.ComboBox({
			width: 130,
			fieldLabel:'有无油机转换箱',
			displayField:'text',
			valueField:'value',
			mode:'local',
			triggerAction: 'all',
			editable: false,
			emptyText:'请选择',						
			store: new Ext.data.SimpleStore({
			fields:['value','text'],
			data:OMS.SITE_FLAG
			})
		});
	this.site_box_position = new Ext.form.TextField({
		fieldLabel: '油机转换箱位置',
		blankText: '请填写油机转换箱位置',
		maxLength:100
	});
	this.power_pole_num = new Ext.form.TextField({
		fieldLabel: '电力杆路号',
		blankText: '请填写电力杆路号',
		maxLength:50
	});
	this.longitude = new Ext.form.TextField({
		fieldLabel: '经度',
		blankText: '请填写经度',
		maxLength:50
	});
	this.latitude = new Ext.form.TextField({
		fieldLabel: '纬度',
		blankText: '请填写纬度',
		maxLength:50
	});
	this.site_group=new Ext.form.ComboBox({
			width: 130,
			fieldLabel:'基站归属组',
			displayField:'text',
			valueField:'value',
			mode:'local',
			editable: false,
			emptyText:'请选择',	
			triggerAction: 'all',					
			store: new Ext.data.SimpleStore({
			fields:['value','text'],
			data:OMS.SITE_GROUP
			})
		});
	this.note = new Ext.form.TextArea({
		fieldLabel: '备注',
		blankText: '请填写备注',
		width:400,
		maxLength:1000
	});
	this.btnSave = new Ext.Button({
            text: '保存',
            cls: 'x-btn-text-icon btn-save',
            handler: this.save,
            scope: this
    });
	this.form = new Ext.form.FormPanel({
        bodyStyle: 'padding: 5px 5px 0',
        frame:true,
        autoHeight: true,
        labelAlign: 'right',
        labelWidth: 100,
        layout:'table',
        layoutConfig:{columns:2},
        items: [
                {layout:'form',items:[this.site_num]},
                {layout:'form',items: [this.site_title]},
                {layout:'form',items: [this.site_att]},
                {layout:'form', items:[this.site_position]},
                {layout:'form', items:[this.site_dep]},
                {layout:'form', items:[this.power]},
                {layout:'form', items: [this.power_ensure]},
                {layout:'form', items:[this.site_box]},
                {layout:'form', items:[this.site_box_position]},
                {layout:'form', items:[this.power_pole_num]},
                {layout:'form', items:[this.longitude]},
                {layout:'form', items:[this.latitude]},
                {colspan:2, layout:'form', items:[this.note]},
                {layout:'form', items:[this.site_group]}
                
		]
    });
	
	Site.Add.superclass.constructor.call(this,{
		title: '基站信息',
        bodyStyle: 'padding: 1px 1px 0',
        width: 700,
        resizable: false,
        frame:true,
        closeAction: 'hide',
        items: [this.form],
        buttons: [this.btnSave,{
            text: '关闭',
            cls: 'x-btn-text-icon btn-cancel',
            handler: this.hide.createDelegate(this, [])
        }]
	});	
};

Ext.extend(Site.Add, Ext.Window, {		
	initEdit:function(data){
		this.site_id.setValue(data.SITE_ID);
		this.site_num.setValue(data.SITE_NUM);
		this.site_title.setValue(data.SITE_TITLE);
		this.site_att.setValue(data.SITE_ATT);
		this.site_position.setValue(data.SITE_POSITION);
		this.site_dep.setValue(data.SITE_DEP);
		this.power.setValue(data.POWER);
		this.power_ensure.setValue(data.POWER_ENSURE);
		this.site_box.setValue(data.SITE_BOX);
		this.site_box_position.setValue(data.SITE_BOX_POSITION);
		this.power_pole_num.setValue(data.POWER_POLE_NUM);
		this.longitude.setValue(data.LONGITUDE);
		this.latitude.setValue(data.LATITUDE);
		this.site_group.setValue(data.SITE_GROUP);
		this.note.setValue(data.NOTE);
	},	
	save: function(){
		if(!this.form.getForm().isValid()){
			Utils.info("请将信息填写完整!","系统提示");
			return;
		}
		//if(this.site_id.getValue()){	
		//	this.url='../site/editSite.form?timesnap='+Date.parse(new Date());
		//}else{
		//	this.url='../site/addSite.form?timesnap='+Date.parse(new Date());
		//}
		Ext.Ajax.request({
					url: this.url='../site/editSite.form?timesnap='+Date.parse(new Date()),
					method: 'POST',
					scope:this,
					params: {
						site_id:this.site_id.getValue(),
						site_num:this.site_num.getValue(),
						site_title:this.site_title.getValue(),
						site_att:this.site_att.getValue(),
						site_position:this.site_position.getValue(),
						site_dep:this.site_dep.getValue(),
						power:this.power.getValue(),
						power_ensure:this.power_ensure.getValue(),
						site_box:this.site_box.getValue(),
						site_box_position:this.site_box_position.getValue(),
						power_pole_num:this.power_pole_num.getValue(),
						longitude:this.longitude.getValue(),
						latitude:this.latitude.getValue(),
						site_group:this.site_group.getValue(),
						note:this.note.getValue()
					},
					success:function(resp){
						Utils.info("操作成功!","系统提示");
						Site.Add.instance.hide();		
						Site.List.instance.store.reload();		
					},
					failure:function(resp){
						Utils.info("操作失败!","系统提示");
					}
		});
	}
});
